package databases

import (
	"stforum/global"
	"stforum/global/model"

	"github.com/dingdinglz/dingtools/dingjson"
)

func SetBaseSetting(src string) error {
	global.Logger.Debug("正在将初始化数据入库...")
	return global.SettingDB.SetValue([]byte("setting"), []byte(src))
}

func GetBaseSettingInfo() (model.InstallModel, error) {
	value, err := global.SettingDB.GetValue([]byte("setting"))
	if err != nil {
		return model.InstallModel{}, err
	}
	j := dingjson.NewFromBytes(value)
	var m model.InstallModel
	err = j.ConventToStruct(&m)
	if err != nil {
		return model.InstallModel{}, err
	}
	return m, nil
}

func GetMysqlSettingInfo() (model.InstallMysqlModel, error) {
	value, err := global.SettingDB.GetValue([]byte("setting"))
	if err != nil {
		return model.InstallMysqlModel{}, err
	}
	j := dingjson.NewFromBytes(value)
	var m model.InstallMysqlModel
	err = j.ConventToStruct(&m)
	if err != nil {
		return model.InstallMysqlModel{}, err
	}
	return m, nil
}
